# 封装定位元素和操作
from appium import webdriver
from appium.webdriver.common.appiumby import By

import sys
sys.path.append(r'..')
from common.desired_caps import desired_caps
import logging

# 读取日志配置
logging.config.fileConfig(r'log_conf.ini')
logger = logging.getLogger()
class BasePage():
    def __init__(self,driver):
        self.driver = driver

    # 定位元素
    def find_ele(self,loc):
        ele = self.driver.find_element(*loc)
        return ele
    # 输入
    def input_ele(self,loc,value,desc='输入框'):
        ele = self.find_ele(loc)
        ele.send_keys(value)
        logging.info(f'在{desc}{loc}输入{value}成功')
    # 点击
    def ele_click(self,loc,desc= '按钮'):
        ele = self.find_ele(loc)
        ele.click()
        logging.info(f'{desc}{loc}点击成功')

    # 清空
    def ele_clear(self,loc,desc= '输入框'):
        ele = self.find_ele(loc)
        ele.clear()
        logging.info(f'在{desc}{loc}清空成功')

# 测试
if __name__ == '__main__':
    # 取消定位
    cancel_loc = (By.ID, 'android:id/button2')
    # 跳过定位
    skip_loc = (By.ID, 'com.tal.kaoyan:id/tv_skip')
    # 引入初始化文件
    # 初始化类对象
    driver = desired_caps()
    base_page = BasePage(driver)

    # 执行取消操作
    base_page.ele_click(cancel_loc,'取消按钮')
    base_page.ele_click(skip_loc,'跳过按钮')
